console.log('测试')
// 查询某年某月第一天是周几
const year = 2025
const month = 8;
const firstDay = new Date(year, month - 1, 1);
const weekday = firstDay.getDay();
// console.log(weekday)

// 获取当月天数
// console.log(new Date(year, month, 0).getDate())

// 生成当月日历的二维数组
function getMonthCalendarGrid(year, month) {
  // 本月天数
  const daysInMonth = new Date(year, month, 0).getDate()
  // 第一天周几
  const firstDayWeek = new Date(year, month - 1, 1).getDay();
  // 补满前置空格
  const cells = [];
  for (let i = 0; i < firstDayWeek; i++) {
    cells.push(null)
  }
  // 填入天号
  for (let d = 1; d <= daysInMonth; d++) {
    cells.push(d)
  }
  // 补足结尾空格 使总数为42
  while (cells.length % 7 !== 0 && cells.length != 42) {
    cells.push(null)
  }
  // 切割为一周一行的二维数组
  for (let i = 0; i < cells.length; i += 7) {
    weeks.push(cells.slice(i, i+7))
  }
  console.log(weeks)
  return weeks;
}

getMonthCalendarGrid(year, month)